/* Copyright 2009 Sony Mathew, Minneapolis MN. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */
package com.xsm.lite.event;

/**
 * An event to notify that an event Category was fired 
 *  An event category is identified by an Event's class
 *      (usually when interested in super types). 
 * 
 * @author Sony Mathew
 */
public class CategoryEvent extends Event {

    private static final long serialVersionUID = 1L;

    public interface Listener extends Event.Listener {
        public void onEvent(CategoryEvent e);
    }
    
    @Override
    public void fire(Event.Listener l) {
        ((CategoryEvent.Listener)l).onEvent(this);
    }

    private boolean consumed = false;
    
    private final Event event;
    
    /**
     * The event that fits the category being listened to.
     * 
     * author Sony Mathew
     */
    public CategoryEvent(Event e) {
        this.event = e;
    }

    /**
     * Get the event that met the category being listened to.
     * 
     * author Sony Mathew
     */
    public Event getEvent() {
        return event;
    }
     
    /**
     * A CategoryEvent Listener can consume the specific Event (returned by getEvent()) 
     *  that this category fits such that its listeners don't get notified.
     * Note: This does NOT consume the CategoryEvent itself, which will still be 
     *  forwarded to all Category Listeners always.
     *    
     * author Sony Mathew
     */
    public void consume() {
        this.consumed = true;
    }

    /**
     * Check if the Event (returned by getEvent()) is consumed by any Category Listeners.
     * 
     * @see #consume()
     * 
     * author Sony Mathew
     */
    public boolean isConsumed() {
        return consumed;
    }
        
}
